//控制提醒等待区域margin高度------------------
var wh=window.screen.availHeight;
var marginheight=(wh-80)/2;
$("#waitplace>div").css("marginTop",marginheight+"px");
//新闻点击隐藏选项
var newschoice=document.getElementById("newschoice"); //新闻项
var newschoiceimg=document.getElementById("newschoiceimg");//对应点击图片
var questionchoiceimg=document.getElementById("questionchoiceimg");
var expchoiceimg=document.getElementById("expchoiceimg");
var didian=document.getElementById("didian");//新闻需要隐藏的三个部分
var xueli=document.getElementById("xueli");
var guanxi=document.getElementById("guanxi");

var newsisclick=0;
var questionisclick=0;
var expisclick=0;
newschoice.onclick=function(){
    if(newsisclick==0){
        newsisclick=1;
        newschoiceimg.src="img/hook01.png";
        if(questionisclick===0&&expisclick===0){
            didian.style.display="none";
            xueli.style.display="none";
            guanxi.style.display="none";
        }
    }else if(newsisclick==1){
        newsisclick=0;
        newschoiceimg.src="img/hook-no.png";
        if(questionisclick===0&&expisclick===0){
            didian.style.display="block";
            xueli.style.display="block";
            guanxi.style.display="block";
        }
    }
};
var questionchoice=document.getElementById("questionchoice"); //问题项
questionchoice.onclick=function(){
    if(questionisclick==0){
        console.log(questionisclick);
        questionchoiceimg.src="img/hook01.png";
        questionisclick=1;
        //如果新闻已经隐藏
        if(didian.style.display==="none"){
            didian.style.display="block";
            xueli.style.display="block";
            guanxi.style.display="block";
        }
    }else if(questionisclick==1){
        questionchoiceimg.src="img/hook-no.png";
        questionisclick=0;
        //如果只有新闻还被点击
        if(newsisclick===1&&expisclick==0){
            didian.style.display="none";
            xueli.style.display="none";
            guanxi.style.display="none";
        }
    }
};
var expchoice=document.getElementById("expchoice"); //经验项
expchoice.onclick=function(){
    if(expisclick==0){
        console.log(expisclick);
        expchoiceimg.src="img/hook01.png";
        expisclick=1;
        if(didian.style.display==="none"){
            didian.style.display="block";
            xueli.style.display="block";
            guanxi.style.display="block";
        }
    }else if(expisclick==1){
        expchoiceimg.src="img/hook-no.png";
        expisclick=0;
        if(newsisclick===1&&questionisclick==0){
            didian.style.display="none";
            xueli.style.display="none";
            guanxi.style.display="none";
        }
    }
};
/////////////////////////////////////////////////////////////
var choiced=0;//点击过筛选为1 控制页面内容
var hyischoiced=[];//已经选择的行业
var xqischoiced=[];//已经选择的兴趣
var stype="";//筛选类型
var relation="";//关系
var hobby="";//兴趣ID
var job="";//行业ID
var city="";//定位
var education="";//教育
var currentIndex2=1;//页码
var listajax=0;//搜索列表有数据0
var choiceajax=0;//筛选列表有数据0
var xqchoicenum=0;

var regs=/(searchKey=)([^\s]+)/;
var searchKey="";
if(urlfrom.match(regs)&&urlfrom.match(regs).splice("=")[2]){
    searchKey=urlfrom.match(regs).splice("=")[2];
}
if(searchKey.match("%")){
    searchKey=decodeURIComponent(searchKey);
}
$().ready(function(){
    //最高学历
    document.getElementsByClassName("eudcationbtn")[0].onclick=function(){
        document.getElementById("edchoicepage").style.display="block";
        document.getElementById("page_wrapper").style.display="none";
    };
    var edlist=document.getElementsByClassName("edlist");//学历列表
    var edokbtnimg2=document.getElementsByClassName("edokbtnimg2");//学历选中按钮图片2
    var edokbtnimg1=document.getElementsByClassName("edokbtnimg1");//学历选中按钮图片1
    var eduword="";
    for(var e=0;e<edlist.length;e++){
        edlist[e].index=e;
        edlist[e].onclick=function(event){
            if(edokbtnimg2[this.index].style.display==="none"){
                edokbtnimg2[this.index].style.display="block";
                edokbtnimg1[this.index].style.display="none";
                eduword="";
            }else if(edokbtnimg2[this.index].style.display==="block"){
                for(var i=0;i<edlist.length;i++){
                    edokbtnimg2[i].style.display="block";
                    edokbtnimg1[i].style.display="none";
                    eduword="";
                }
                edokbtnimg2[this.index].style.display="none";
                edokbtnimg1[this.index].style.display="block";
                eduword=edlist[this.index].innerHTML.match(/([\u4E00-\u9FA5]+)/)[0];
                console.log(eduword);
                $(".eduwords").html(eduword);
            }
        }
    }
    document.getElementById("edfinish").onclick=function(){
        document.getElementById("edchoicepage").style.display="none";
        document.getElementById("page_wrapper").style.display="block";
    };
    //所在城市
    var mychoicecityclick=0;//当前点击的那个页面
    $(".mychoicecitybtn").click(function(){
        $(".ctokbtnimg2").css("display","none");
        $("#ctfinish").css("display","none");
        $("#page_wrapper").css("display","none");
        $("#ctchoicepage").css("display","block");
        $("#choicecitybox").css("display","none");
        document.getElementById("ctchoicepage").style.marginTop="98px";
        mychoicecityclick=1;
    });
    //var heightli=0; //城市列表操作
    var hasharr={};//保存第一个首字母的位置
    for(var c1=0;c1<cityarr.length;c1++){
        var cityname=cityarr[c1].match( /[\u4e00-\u9fa5]+/)[0];
        var english=citylist[c1].pinyin.match(/[A-Z]{1}/)[0];
        if(hasharr[english]){}else{
            hasharr[english]=c1;
        }
        $("#citylistul").append("<li class='Cell ctlist'><div class='listtitle "+english+"' style='display:none'>"+english+"</div> <span class='tc_inner' id='"+citylist[c1].zip+"'>"+cityname+"<div class='rt ctokbtn'> <img src='img/pointbtn02.png' class='ctokbtnimg2' style='display: block'/> <img src='img/pointbtn01.png' class='ctokbtnimg1' style='display: none'/> </div> </span> <div class='tc_stroke'></div> </li>");
        //heightli=parseFloat($(".ctlist").eq(1).height());
        //$("div."+english).css("display","block");
    }
    //hash。A不是0 更改
    hasharr.A=0;
    for(var key in hasharr){
        $("div.listtitle").eq(hasharr[key]).css("display","block");
    }
    var choicenum=0;
    $("li.ctlist span.tc_inner").click(function(e){//列表点击
        var word=e.target.innerHTML.match(/[\u4e00-\u9fa5]+/)[0];

        var s1=e.target.getElementsByTagName("img");
        var spid="s"+e.target.id;

        if(mychoicecityclick===1){
            $(".myctywords span").remove();
            $(".myctywords").append("<span id='s"+spid+"'>"+word+"</span>");
            $("#page_wrapper").css("display","block");
            $("#ctchoicepage").css("display","none");
            $(".ctokbtnimg2").css("display","block");
            $("#ctfinish").css("display","block");
            $("#choicecitybox").css("display","block");
            //$("#ctchoicepage").csss("margin-top","142px");
            document.getElementById("ctchoicepage").style.marginTop="142px";
            //console.log("mychoicecityclick:"+mychoicecityclick);
            mychoicecityclick=0;
        }else{
            //console.log("mychoicecityclick:"+mychoicecityclick);
            if(s1[0].style.display==="block"){
                if(choicenum<3){
                    s1[0].style.display="none";
                    s1[1].style.display="block";
                    choicenum++;
                    $("#choicecitybox").append("<span id='"+spid+"'>"+word+"</span>")
                }
            }else if(s1[0].style.display==="none"){
                s1[0].style.display="block";
                s1[1].style.display="none";
                var addspan=document.getElementsByTagName("span");
                for(var i=0;i<addspan.length;i++){
                    addspan[i].index=i;
                    if(addspan[i].innerHTML.match(/[\u4e00-\u9fa5]+/)[0]===word){
                        var spanname="span#"+spid;
                        $("span#"+spid).remove();
                        choicenum--;
                        break;
                    }else{
                        console.log("没有找到span")
                    }
                }
            }
        }
    });
    var englishbtn=document.querySelectorAll(".rightnav div");//导航条跳转
    var tonum=0;
    for(var en=0;en<englishbtn.length;en++){
        englishbtn[en].onclick=function(e){
            var num= parseFloat(e.target.dataset.num)-1;
            //var listtitleheight=$("div.listtitle").eq(0).height();  36px
            eval("var re = /^"+e.target.innerHTML+"/;");
            for(var i=0;i<citylist.length;i++){
                citylist[i].index=i;
                if(citylist[i].pinyin.match(re)){
                    console.log(citylist[i].index);
                    tonum=citylist[i].index;
                    break;
                }
            }
            var heightdiv=parseFloat($(".ctlist").eq(1).height()*tonum)+parseFloat(36*num);
            console.log("列表"+parseFloat($(".ctlist").eq(1).height()*tonum));
            console.log("标题"+parseFloat(36*num));
            console.log("总和："+heightdiv);
            $(window).scrollTop(heightdiv);
        }
    }
    $("#csearchbtn").click(function(){//搜索跳转
        var word=$("#csearchinput").val();
        var english=pinyin.getCamelChars(word).match(/([A-Z])/)[0];
        var num=0;
        for(var i=0;i<englishbtn.length;i++){
            if(englishbtn[i].innerHTML===english){
                num=englishbtn[i].dataset.num;
            }
        }

        if($("#csearchinput").val().match(/[\u4e00-\u9fa5]+/)){
            var heightli=parseFloat($(".ctlist").eq(1).height());
            for(var x=0;x<citylist.length;x++){
                citylist[x].index=x;
                if(citylist[x].label.match($("#csearchinput").val())){
                    console.log(citylist[x].index);
                    console.log(citylist[x].name);
                    var heightdiv=parseFloat(heightli*(citylist[x].index))+36*num;
                    console.log(heightdiv);
                    $(window).scrollTop(heightdiv);
                    break;
                }
            }
        }
    });
    $("#ctfinish").click(function(){ //关闭城市列表
        $("#ctchoicepage").css("display","none");
        $("#page_wrapper").css("display","block");
        $(".ctywords span").remove();
        var showspan=document.querySelectorAll("#choicecitybox span");
        for(var i=0;i<showspan.length;i++){
            $(".ctywords").append("<span>"+showspan[i].innerHTML+"</span>");
        }

    });
    //获取行业列表
    $(".hangyelistbtn").click(function(){
        $("#choicepage").css("display","block");
        $("#page_wrapper").css("display","none");
        $.ajax({
            type:"get",
            url:joblisturl,
            success:function(data){
                for(var i=0;i<data.Data.length;i++){
                    $("#ts_cells").append("<li class='Cell'><span class='tc_inner' id='"+data.Data[i].id+"'>"+data.Data[i].typename+"</span><div class='tc_stroke'></div></li>");
                }
            }
        });
    });
    //行业列表项添加点击事件
    $(".bigbox1").delegate("#choicepage .tc_inner","click",function(event){
        if(event.target.className=="tc_inner"){
            choicenum++;
            event.target.className+=" isclicked";
            ///////////////////////////////
            if(choicenum<=3){
                $("#choicedbox").append("<span id='"+event.target.id+"'>"+event.target.innerHTML+"</span>");
            }else if(choicenum>3){
                $("#choicedbox span:first-child").remove();
                $("#choicedbox").append("<span id='"+event.target.id+"'>"+event.target.innerHTML+"</span>");
                choicenum=3;
            }
            ///////////////////////////////
        }else if(event.target.className=="tc_inner isclicked"){
            event.target.className="tc_inner";
            $("#choicedbox span#"+event.target.id).remove();
            choicenum--;
        }
    });
    $("#finish").click(function(){
        hyischoiced=[];
        for(var r=0;r< $("#choicedbox span").length;r++){
            hyischoiced.push({"id":$("#choicedbox span")[r].id,"typename":$("#choicedbox span")[r].innerHTML});
            console.log(hyischoiced);
        };
        $("#choicepage").css("display","none");
        $("#page_wrapper").css("display","block");
        $(".hangyewords span").remove();
        for(var r2=0;r2<hyischoiced.length;r2++){
            $(".hangyewords").append("<span>"+hyischoiced[r2].typename+"</span>");
            if($(".hangyewords span").length>3){
                $(".hangyewords span:first").remove();
            }
        }
    });
    //获取兴趣列表
    $(".xingqulistbtn").click(function(){
        $("#xqchoicepage").css("display","block");
        $("#page_wrapper").css("display","none");
        $.ajax({
            type:"get",
            url:hobbylisturl,
            success:function(data){
                for(var i=0;i<data.Data.length;i++){
                    $("#xqts_cells").append("<li class='Cell'><span class='tc_inner' id='"+data.Data[i].id+"'>"+data.Data[i].typename+"</span><div class='tc_stroke'></div></li>");
                }
            }
        });
    });
    //兴趣列表项添加点击事件
    $(".bigbox2").delegate("#xqchoicepage .tc_inner","click",function(event){
        if(event.target.className=="tc_inner"){
            xqchoicenum++;
            event.target.className+=" isclicked";
            if(xqchoicenum<=3){
                $("#xqchoicedbox").append("<span id='"+event.target.id+"'>"+event.target.innerHTML+"</span>");
            }else if(xqchoicenum>3){
                $("#xqchoicedbox span:first-child").remove();
                $("#xqchoicedbox").append("<span id='"+event.target.id+"'>"+event.target.innerHTML+"</span>");
                xqchoicenum=3;
            }
        }else if(event.target.className=="tc_inner isclicked"){
            event.target.className="tc_inner";
            $("#xqchoicedbox span#"+event.target.id).remove();
            xqchoicenum--;
        }
    });
    $("#xqfinish").click(function(){
        xqischoiced=[];
        for(var i=0;i< $("#xqchoicedbox span").length;i++){
            xqischoiced.push({"id":$("#xqchoicedbox span")[i].id,"typename":$("#xqchoicedbox span")[i].innerHTML});
        };
        $("#xqchoicepage").css("display","none");
        $("#page_wrapper").css("display","block");
        $(".xingquwords span").remove();
        for(var r=0;r<xqischoiced.length;r++){
            $(".xingquwords").append("<span>"+xqischoiced[r].typename+"</span>");
            if($(".xingquwords>span").length>3){
                $(".xingquwords>span:first-child").remove();
            }
        }
    });
    //好友关系
    document.getElementsByClassName("relabtn")[0].onclick=function(){
        document.getElementById("rechoicepage").style.display="block";
        document.getElementById("page_wrapper").style.display="none";
    };
    var fribtn=document.getElementById("fribtn");//好友
    var fribtnclick=0;//点击状态 0没点
    var gfribtn=document.getElementById("gfribtn");//密友
    var gfribtnclick=0;
    var strbtn=document.getElementById("strbtn");//陌生人
    var strbtnclick=0;
    var reokbtnimg2=document.getElementsByClassName("reokbtnimg2");//关系选中按钮图片2
    var reokbtnimg1=document.getElementsByClassName("reokbtnimg1");//关系选中按钮图片1

    fribtn.onclick=function(){
        if(reokbtnimg2[0].style.display==="block"){
            fribtnclick=1;
            reokbtnimg2[0].style.display="none";
            reokbtnimg1[0].style.display="block";
        }else if(reokbtnimg2[0].style.display==="none"){
            fribtnclick=0;
            reokbtnimg2[0].style.display="block";
            reokbtnimg1[0].style.display="none";
        }
    };
    gfribtn.onclick=function(){
        if(reokbtnimg2[1].style.display==="block"){
            gfribtnclick=1;
            reokbtnimg2[1].style.display="none";
            reokbtnimg1[1].style.display="block";
        }else if(reokbtnimg2[1].style.display==="none"){
            gfribtnclick=0;
            reokbtnimg2[1].style.display="block";
            reokbtnimg1[1].style.display="none";
        }
    };
    strbtn.onclick=function(){
        if(reokbtnimg2[2].style.display==="block"){
            strbtnclick=1;
            reokbtnimg2[2].style.display="none";
            reokbtnimg1[2].style.display="block";
        }else if(reokbtnimg2[2].style.display==="none"){
            strbtnclick=0;
            reokbtnimg2[2].style.display="block";
            reokbtnimg1[2].style.display="none";
        }
    };
    //关系
    document.getElementById("refinish").onclick=function(){
        document.getElementById("rechoicepage").style.display="none";
        document.getElementById("page_wrapper").style.display="block";
        if(fribtnclick===1&&gfribtnclick===0&&strbtnclick===0){
            relation=1;
            $("#relawords").html("好友");
        }else if(fribtnclick===0&&gfribtnclick===1&&strbtnclick===0){
            relation=2;
            $("#relawords").html("密友");
        }else if(fribtnclick===0&&gfribtnclick===0&&strbtnclick===1){
            relation=3;
            $("#relawords").html("陌生人");
        }else if(fribtnclick===1&&gfribtnclick===1&&strbtnclick===0){
            relation=4;
            $("#relawords").html("好友及密友");
        }else if(fribtnclick===0&&gfribtnclick===1&&strbtnclick===1){
            relation=6;
            $("#relawords").html("密友及陌生人");
        }else if(fribtnclick===1&&gfribtnclick===0&&strbtnclick===1){
            relation=5;
            $("#relawords").html("好友及陌生人");
        }else if(fribtnclick===1&&gfribtnclick===1&&strbtnclick===1||(fribtnclick===0&&gfribtnclick===0&&strbtnclick===0)){
            relation=7;
            $("#relawords").html("所有");
        }
    };
//完成按钮
    var clicktim="can";//完成按钮点击次数
    $("#oksearchbtn").click(function(){
        currentIndex2=1;
        //行业兴趣
        //行业兴趣反了
        for(var i=0;i<hyischoiced.length;i++){
            job+=hyischoiced[i].id+",";
        };
        for(var r=0;r<xqischoiced.length;r++){
            hobby+=xqischoiced[r].id+",";
        };
        hobby=hobby.substring(0,hobby.length-1);
        job=job.substring(0,job.length-1);
        //地点
        if(document.querySelectorAll(".myctywords span").length>0){
            var showmyspan=document.querySelector(".myctywords span");
            if(document.querySelector(".myctywords span").innerHTML){
                city=document.querySelector(".myctywords span").innerHTML;
            }
        }
        //学历
        education=$(".eduwords").html();  //教育
        //筛选类型
        if(newsisclick===1&&questionisclick===0&&expisclick===0){
            stype=1;
        }else if(newsisclick===0&&questionisclick===1&&expisclick===0){
            stype=2;
        }else if(newsisclick===0&&questionisclick===0&&expisclick===1){
            stype=3;
        }else if(newsisclick===1&&questionisclick===1&&expisclick===0){
            stype=4;
        }else if(newsisclick===0&&questionisclick===1&&expisclick===1){
            stype=5;
        }else if(newsisclick===1&&questionisclick===0&&expisclick===1){
            stype=6;
        }else if(newsisclick===1&&questionisclick===1&&expisclick===1||(newsisclick===0&&questionisclick===0&&expisclick===0)){
            stype=7;
        }
        $("#waitplace").css("display","block");
        if(clicktim=="can"){
            $(".searchlist-box div").remove();
            if(stype==""&&hobby==""&&job==""&&city==""&&education==""&&relation==""){
                choiced=0;
                chiocesearchajax(stype,hobby,job,city,education,relation,currentIndex2);
            }else{
                choiced=1;
                chiocesearchajax(stype,hobby,job,city,education,relation,currentIndex2);
            }
        }
    });
});
//提交数据 choicesearchurl
function chiocesearchajax(stype,hobby,job,city,education,relation,currentIndex2){
    $.cookie("GJstype",stype);
    $.cookie("GJhoddy","");
    $.cookie("GJjob","");
    $.cookie("GJcity",city);
    $.cookie("GJeducation",education);
    $.cookie("GJrelation",relation);
    $.cookie("GJcurrent",currentIndex2);
    clicktim="no";
    if(choiceajax===0){
        $.ajax({
            type:"get",
            datatype:"json",
            url:choicesearchurl+"?userId="+id+"&searchKey="+searchKey+"&stype="+stype+"&hobbyIds="+hobby+"&jobIds="+job+"&place="+city+"&education="+education+"&relatetion="+relation+"&currentIndex="+currentIndex2+"&pageSize=6",
            success:function(d){
                console.log(d);
                clicktim="can";//完成可以点击
                if(d.Data&&d.Data.length>0){
                    if(d.Data.length<6){
                        $("#waiting").css("display","none");
                        $("#nonews").css("display","block");
                    }
                    choiceajax=0;
                    for(var i=0;i<d.Data.length;i++){
                        var regt=/([0-9\-]+)/;
                        var tim=d.Data[i].ctime.match(regt)[0];
                        var hrefto="";
                        if(d.Data[i].user){
                            if(d.Data[i].user.userId===id){
                                hrefto="setpage.html";
                            }else{
                                hrefto="otherpeoplepage.html?otherid="+d.Data[i].user.userId;
                            }
                        }
                        //新闻
                        if(d.Data[i].contenttype===1){
                            $(".searchlist-box").append("<div class='feed_item'> <div class='title'> <a class='BoardItemTitle'>"+d.Data[i].name+"</a> </div><div class='EventHeader'> <span><a>"+d.Data[i].fromsite+"</a></span> <span class='timestamp'> · "+tim+"</span> </div><div class='answer_count_row'> <a href='"+d.Data[i].link+"'>查看详情</a> </div> </div>");
                        }
                        //问题 <span class='TopicNameSpan TopicName'> · 密友</span>   <div class='preview_only'> <div>"+d.Data[i].content+"</div> </div>
                        if(d.Data[i].contenttype===2){
                            $(".searchlist-box").append("<div class='feed_item'> <div class='title'> <a class='BoardItemTitle'>"+d.Data[i].name+"</a> </div> <div class='EventHeader'> <span><a "+hrefto+">"+d.Data[i].user.nick+"</a></span>  <span class='timestamp'> · "+tim+"</span> <span class='scoreimg'><img src='../img/wen01.png'><img src='../img/money04.png'/>"+parseFloat(d.Data[i].score)/100+"</span><div class='answer_count_row'> <a href='questiondetail.html?qid="+ d.Data[i].contentId+"'>查看详情</a> </div> </div> </div>");
                        }
                        //经验 <span class='TopicNameSpan TopicName'> · 密友</span>  <div class='preview_only'> <div>"+d.Data[i].content+"</div>
                        if(d.Data[i].contenttype===3){
                            $(".searchlist-box").append("<div class='feed_item'> <div class='title'> <a class='BoardItemTitle'>"+d.Data[i].name+"</a> </div> <div class='EventHeader'> <span><a "+hrefto+">"+d.Data[i].user.nick+"</a></span> <span class='timestamp'> · "+tim+"</span> <span class='scoreimg'><img src='../img/jing01.png'><img src='../img/money04.png'/>"+parseFloat(d.Data[i].score)/100+"</span></div> <div class='answer_count_row'> <a  onclick='moneytest(this)' data-euser='"+d.Data[i].user.userId+"' data-score='"+d.Data[i].score+"' data-eid='"+d.Data[i].contentId+"'>查看详情</a> </div></div>  </div>");
                        }
                    };
                }else{
                    choiceajax=1;
                    $("#waiting").css("display","none");
                    $("#nonews").css("display","block");
                }
                $("#page_wrapper1").css("display","block");
                $("#choicesearch").css("display","none");
                $("#waitplace").css("display","none");
            }
        })
    }else{
        clicktim="can";//完成可以点击
        console.log("没数据了");
        $("#waitplace").css("display","none");
        $("#waiting").css("display","none");
        $("#nonews").css("display","block");
        $("#page_wrapper1").css("display","block");
        $("#choicesearch").css("display","none");
    }
}